package cn.kpi.common.utils;

import java.io.File;
import java.io.InputStream;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class ExeclUtils {
	private boolean isExcel2003;

	public boolean isExcel2003() {
		return isExcel2003;
	}

	public void setExcel2003(boolean isExcel2003) {
		this.isExcel2003 = isExcel2003;
	}

	public boolean ValidateExcel(String filePath) {
		/** 检查文件名是否为空或者是否是Excel格式的文件 */
		String prefix = filePath.substring(filePath.lastIndexOf("."));
		if (filePath == null || prefix != "xls" || prefix != "xlsx") {
			// errorInfo = "文件名不是excel格式";
			return false;
		} else {
			if (prefix == "xls") {
				this.setExcel2003(true);
			}
		}
		/** 检查文件是否存在 */
		File file = new File(filePath);
		if (file == null || !file.exists()) {
			// errorInfo = "文件不存在";
			return false;
		}
		return true;
	}

	public void dd(InputStream inputStream, boolean isExcel2003) {
		Workbook wb = null;
		try {
			if (isExcel2003) {
				wb = new HSSFWorkbook(inputStream);
			} else {
				wb = new XSSFWorkbook(inputStream);
			}
		} catch (Exception ex) {

		}
	}
}
